using System;
namespace Util
{
    /// <summary>
    /// 静态单例对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class Singleton<T> where T: Singleton<T>, new()
    {
        protected Singleton(){}
        private static T sIns;
        private static readonly object _lock = new object();
        public static T Ins
        {
            get
            {
                if (sIns == null)
                {
                    lock (_lock)
                    {
                        if (sIns == null)
                        {
                            sIns = new T();
                            sIns.OnCreate();
                        }
                    }
                }
                return sIns;
            }
        }

        /// <summary>
        /// 对内初始化接口
        /// </summary>
        protected virtual void OnCreate(){}

        /// <summary>
        /// 对外初始化接口
        /// </summary>
        public virtual void Init(){}

        /// <summary>
        /// 对外销毁接口
        /// </summary>
        public virtual void Release()
        {
            sIns = null;
        }
    }
}

